package cliente.gui;

import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

import servidor.dominio.*;

import comun.dto.*;

/**
 *
 * @author German
 */
public class GUIListadoDeEmpleados extends JFrame {

    /** Creates new form GUIListadoDeEmpleados */
    public GUIListadoDeEmpleados() {
        initComponents();
        this.setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaEmpleado = new javax.swing.JTable();
        eleccion = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        cuit = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cuil = new javax.swing.JTextField();
        listar = new javax.swing.JButton();
        salir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Listado de Empleados");
       

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Listado de Empleados"));

        tablaEmpleado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "Apellido", "Cuil", "Categoria", "Empresa", "Fecha de Ingreso", "Nro de Cuenta", "Sucursal", "Banco"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tablaEmpleado);

        eleccion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cuit Empresa", "Cuil Empleado", "Listar Todos" }));

        jLabel1.setText("Buscar Por: ");

        jLabel2.setText("Ingrese Cuit: ");

        jLabel3.setText("Ingrese Cuil: ");

        cuil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cuilActionPerformed(evt);
            }
        });

        listar.setText("Listar");

        salir.setText("Salir");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(eleccion, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(85, 85, 85)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cuit, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cuil, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)))
                .addGap(45, 45, 45)
                .addComponent(listar, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(203, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 888, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(375, 375, 375)
                .addComponent(salir, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(415, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(listar)
                        .addGap(32, 32, 32))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(eleccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(cuit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(cuil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(salir)
                .addGap(175, 175, 175))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>

private void cuilActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUIListadoDeEmpleados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUIListadoDeEmpleados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUIListadoDeEmpleados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUIListadoDeEmpleados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GUIListadoDeEmpleados().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JTextField cuil;
    private javax.swing.JTextField cuit;
    private javax.swing.JComboBox eleccion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton listar;
    private javax.swing.JButton salir;
    private javax.swing.JTable tablaEmpleado;
    // End of variables declaration

    /**
     * @return the cuil
     */
    public javax.swing.JTextField getCuil() {
        return cuil;
    }

    /**
     * @param cuil the cuil to set
     */
    public void setCuil(javax.swing.JTextField cuil) {
        this.cuil = cuil;
    }

    /**
     * @return the cuit
     */
    public javax.swing.JTextField getCuit() {
        return cuit;
    }

    /**
     * @param cuit the cuit to set
     */
    public void setCuit(javax.swing.JTextField cuit) {
        this.cuit = cuit;
    }

    /**
     * @return the eleccion
     */
    public javax.swing.JComboBox getEleccion() {
        return eleccion;
    }

    /**
     * @param eleccion the eleccion to set
     */
    public void setEleccion(javax.swing.JComboBox eleccion) {
        this.eleccion = eleccion;
    }

    /**
     * @return the listar
     */
    public javax.swing.JButton getListar() {
        return listar;
    }

    /**
     * @param listar the listar to set
     */
    public void setListar(javax.swing.JButton listar) {
        this.listar = listar;
    }

    /**
     * @return the salir
     */
    public javax.swing.JButton getSalir() {
        return salir;
    }

    /**
     * @param salir the salir to set
     */
    public void setSalir(javax.swing.JButton salir) {
        this.salir = salir;
    }

    /**
     * @return the tablaEmpleado
     */
    public javax.swing.JTable getTablaEmpleado() {
        return tablaEmpleado;
    }

    /**
     * @param tablaEmpleado the tablaEmpleado to set
     */
    public void setTablaEmpleado(javax.swing.JTable tablaEmpleado) {
        this.tablaEmpleado = tablaEmpleado;
    }
    
    public void setTablaEmpleados(java.util.Vector  empleados){
		EmpleadoDTO empl;
		int i=0;
		Object datos[]=new Object[4];
		while (!empleados.isEmpty()){
			DefaultTableModel m=(DefaultTableModel)tablaEmpleado.getModel();
			String[] filavacia=new String[8];
			m.addRow(filavacia);
			empl=(EmpleadoDTO) empleados.get(0);
			tablaEmpleado.setValueAt(empl.getNombre(), i, 0);
			tablaEmpleado.setValueAt(empl.getApellido(), i, 1);
			tablaEmpleado.setValueAt(empl.getCuil(), i, 2);
			//aca hay un problema
			tablaEmpleado.setValueAt(empl.getCategoria().getNombre(), i, 3);
			tablaEmpleado.setValueAt(empl.getCliente().getNombre(), i, 4);
			tablaEmpleado.setValueAt(empl.getFechaIngreso(),i,5);
			tablaEmpleado.setValueAt(empl.getNroDeCuenta(),i,6);
			tablaEmpleado.setValueAt(empl.getNroDeSucursal(),i,7);
			tablaEmpleado.setValueAt(empl.getBanco(),i,8);
			
			
			empleados.remove(0);
			i++;
			
		}
	}
    
    public void setTablaEmpleado(Empleado  empleado){
 		//EmpleadoDTO empl;
 	//	int i=0;
 		Object datos[]=new Object[4];
 		//while (!empleados.isEmpty()){
 			DefaultTableModel m=(DefaultTableModel)tablaEmpleado.getModel();
 			String[] filavacia=new String[8];
 			m.addRow(filavacia);
 			//empl=(EmpleadoDTO) empleados.get(0);
 			tablaEmpleado.setValueAt(empleado.getNombre(), 0, 0);
 			tablaEmpleado.setValueAt(empleado.getApellido(), 0, 1);
 			tablaEmpleado.setValueAt(empleado.getCuil(), 0, 2);
 			//aca hay un problema
 			tablaEmpleado.setValueAt(empleado.getCategoria().getNombre(), 0, 3);
 			tablaEmpleado.setValueAt(empleado.getCliente().getNombre(), 0, 4);
 			tablaEmpleado.setValueAt(empleado.getFechaIngreso(),0,5);
 			tablaEmpleado.setValueAt(empleado.getNroDeCuenta(),0,6);
 			tablaEmpleado.setValueAt(empleado.getNroDeSucursal(),0,7);
 			tablaEmpleado.setValueAt(empleado.getBanco(),0,8);
 			
 			
 			//empleados.remove(0);
 			//i++;
 			
 	//	}
 	}
    
	public void setTablaEmpleado(){
		tablaEmpleado.setModel(new javax.swing.table.DefaultTableModel(
				new Object [][] {
					
				},
				new String [] {
						"Nombre","Apellido", "Cuil", "Categoria", "Empresa", "Fecha de Ingreso", "Nro deCuenta", "Sucursal", "Banco"
				}
				));
	}
    
    public void setActionListeners(ActionListener lis) {
        salir.addActionListener(lis);
        eleccion.addActionListener(lis);
        listar.addActionListener(lis);
        //opcion.addActionListener(lis);
    }

}
